luci-app-acme: Guess the system domain and pre-fill it to domains.
authorSergey Ponomarev <[email protected]>
Sat, 1 Jun 2024 17:19:41 +0000 (20:19 +0300)
committerToke Høiland-Jørgensen <[email protected]>
Tue, 7 Oct 2025 12:01:06 +0000 (14:01 +0200)
Check if the hostname is FQDN (e.g. has least one dot).
Check if the domain in the browser is not an IP and FQDN.

Signed-off-by: Sergey Ponomarev <[email protected]>
applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js
applications/luci-app-acme/root/usr/share/rpcd/acl.d/luci-app-acme.json

index 937a931269013a6ce081b5ed69284803c346731e..c8f2a521166a9aea524890dfe972582e2c0f97f6 100644 (file)
@@ -19,6 +19,7 @@ return view.extend({
                        }),
                        L.resolveDefault(fs.exec_direct('/usr/libexec/acmesh-dnsinfo.sh'), ''),
                        L.resolveDefault(fs.stat('/usr/lib/acme/client/dnsapi'), null),
+                       L.resolveDefault(fs.lines('/proc/sys/kernel/hostname'), ''),
                ]);
        },
 
@@ -27,6 +28,8 @@ return view.extend({
                let dnsApiInfoText = data[1];
                let apiInfos = dnsapi.parseFile(dnsApiInfoText);
                let hasDnsApi = data[2] != null;
+               let hostname = data[3];
+               let systemDomain = _guessDomain(hostname);
                let wikiUrl = 'https://github.com/acmesh-official/acme.sh/wiki/';
                let wikiInstructionUrl = wikiUrl + 'dnsapi';
                let m, s, o;
@@ -97,6 +100,9 @@ return view.extend({
                                "The first name will be the subject name, subsequent names will be alt names. " +
                                "Note that all domain names must point at the router in the global DNS."));
                o.datatype = "list(string)";
+               if (systemDomain) {
+                       o.default = [systemDomain];
+               }
                o.validate = function (section_id, value) {
                        if (!value) {
                                return true;
@@ -271,6 +277,15 @@ return view.extend({
        }
 });
 
+function _isFqdn(domain) {
+       // Is not an IP i.e. starts from alphanumeric and has least one dot
+       return /[a-z0-9-]\..*$/.test(domain) && !/[0-9-]\..*$/.test(domain);
+}
+
+function _guessDomain(hostname) {
+       return _isFqdn(hostname) ? hostname : (_isFqdn(window.location.hostname) ? window.location.hostname : '');
+}
+
 
 function _addDnsProviderField(s, apiId, opt, isOptsAlt) {
        let desc = '<code>' + opt.Name + '</code> ' + opt.Description;
index 97e5d65f5db1bfd4249514441679be414d621047..a8bd9f9fb30490e5c4431c9655706e8f1965cc11 100644 (file)
@@ -4,6 +4,7 @@
                 "read": {
                         "cgi-io": [ "exec" ],
                         "file": {
+                                "/proc/sys/kernel/hostname": [ "read" ],
                                 "/etc/ssl/acme": [ "list" ],
                                 "/usr/libexec/acmesh-dnsinfo.sh": [ "exec" ]
                         },